home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.05 May 91 / StripStyle FKEY / Strip Style FKEY.Doc < prev    next >
Encoding:
Text File  |  1991-02-11  |  1.7 KB  |  43 lines  |  [TEXT/ttxt]

  1. Lately, I've found myself repeatedly frustrated by the simple operation of copying and pasting text in HyperCard 2.0.  The problem occurs when I go to paste the text.  It seems that HyperCard (many other applications) now copy the style of the text as well as the text itself.  This is great until you have to go to the different menus to set the font, size, and style.  Here is the code for a short little FKEY that strips away the style from the scrap, leaving only text.
  2.  
  3. Handle NewClearSysHandle(long size){
  4.     asm{
  5.         move.l            size,d0
  6.         NewHandle    CLEAR+SYS
  7.         move.l            a0,d0
  8.         }
  9.     }
  10.     
  11. void main(void){
  12.     long    scrapsize, offset;
  13.     Handle     h;
  14.     
  15.     scrapsize=0L;
  16.     h=0L;
  17.     if (!(h=NewClearSysHandle(0)))
  18.         goto returnpoint;
  19.     scrapsize=GetScrap(h,'TEXT',&offset);
  20.     if (scrapsize>0){                                                
  21.         SetHandleSize(h,scrapsize+(scrapsize &1)); /*make Handle even size*/
  22.         ZeroScrap();
  23.         PutScrap(scrapsize,'TEXT',*h);
  24.         SystemEdit(3); /*  Tricky part */
  25.         }
  26. returnpoint:
  27.     if (h)
  28.             DisposHandle(h);
  29.     }
  30.  
  31. See the call to SystemEdit(3)?  Well it took me FOREVER to figure that one out.  The system won't recognize that the scrap has changed until you do it.  I hope I'm not the only programmer out there that's had problems with this one! 
  32. For Think C project…
  33.     Project type->Code Resource
  34.         Type:  FKEY (all capitols)
  35.         ID:  7 (this is also the number key that invokes FKEY)
  36.         Attrs:  20 (purgable)
  37.         File Type:  rsrc (ResEdit)
  38.         Creator:  RSED (ResEdit)
  39.         Name:  Strip Style FKEY
  40.  
  41. Tom Nielsen, Recommended Testing
  42.  
  43. Note that I included a full C Project, and MacPaint document showing the Project settings.  MacTutor can use the source and this note anyway it sees fit (just so long as I can show the article to my mother and she would believe that I wrote it).